package com.tanhua.admin.controller;

import cn.hutool.core.date.DateTime;
import com.tanhua.admin.service.DashboardService;
import com.tanhua.model.vo.AnalysisSummaryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/dashboard")
public class DashboardController {

    @Autowired
    private DashboardService dashboardService;

    /**
     * 概要统计
     *
     * @return
     */
    @GetMapping("/summary")
    public ResponseEntity getSummary() {
        String dateTimeString = "2021-11-25";
        AnalysisSummaryVo summary = dashboardService.getSummary(dateTimeString);
        return ResponseEntity.ok(summary);
    }

    /**
     * 新增、活跃用户、次日留存率
     *
     * @param sd
     * @param ed
     * @param type
     * @return
     */
    @GetMapping("/users")
    public ResponseEntity getUsers(Long sd, Long ed, String type) {
        DateTime of = DateTime.of(sd);
        DateTime of1 = DateTime.of(ed);
        Map<String, List> map = dashboardService.getUsers(of, of1, type);
        return ResponseEntity.ok(map);
    }
}